import 'package:flutter/material.dart';



class Mydialog extends Dialog{
  //定义接受参数
  final String title;
  final String content;

  //定义接受函数，点击关闭按钮传参
  //？：为可控类型
  final Function()? onTap;

  const Mydialog({
    Key? key,
    required this.title,
    required this.content,
    required this.onTap,
  }) : super(key: key);

  //实现方法
  @override
  Widget build(BuildContext context){
    return Material(
      //设置背景透明
      type: MaterialType.transparency,
      child: Center(
        //Container在外层时，会铺满整个屏幕，所以要再套一层Center才会使Container宽高正常
        child: Container(
          height: 250,
          width: 250,
          color: Colors.white,
          child: Column(
            children: [
              //上下间距
              Padding(
                padding: EdgeInsets.all(5),
                child: Stack(
                  children: [
                    Align(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        //接受参数
                        title,
                        style: TextStyle(
                          fontSize: 18,
                        ),
                      ),
                    ),
                    Align(
                      alignment: Alignment.centerRight,
                      //点击功能组件
                      child: InkWell(
                        child: const Icon(Icons.close),
                        // onTap: (){
                        //   print("close");
                        //   //点击关闭
                        //   Navigator.pop(context);
                        // },
                        //设置成可控函数
                        onTap: onTap,
                      ),
                    ),
                  ],
                ),
              ),

              const Divider(),

              Container(
                padding: const EdgeInsets.all(10),
                //用外部容器的宽高
                width: double.infinity,
                child: Text(content,
                  style: const TextStyle(
                    fontSize: 14,
                  )),
              ),


            ],
          ),
        ),
      )
    );
  }



}